<!DOCTYPE html>

<html>

	<head>

		<meta charset="UTF-8">

		<title>Table</title>

		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />

		<link rel="stylesheet" href="/addons/hc_answer/template/css/global.css" media="all">

		<link rel="stylesheet" type="text/css" href="/addons/hc_answer/template/plugins/font-awesome/css/font-awesome.css">

		<link rel="stylesheet" href="/addons/hc_answer/template/css/table.css" />

	</head>
	<body>
		<div class="admin-main">
			<blockquote class="layui-elem-quote">
				<div class="layui-inline">
					<select class="layui-input" id="robot">
						<option value="">全部</option>
						<option value="1" {if $robot == 1}selected="selected"{/if}>用户</option>
						<option value="2" {if $robot == 2}selected="selected"{/if}>机器人</option>
					</select>

				</div>

				<div class="layui-inline">

			    	<input class="layui-input" id="nickname" value="{$nickname}" placeholder="昵称">

			  	</div>

				<a href="javascript:;" class="layui-btn layui-btn-small" id="search">

					<i class="layui-icon">&#xe615;</i> 搜索

				</a>

				<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-small" id="add">

					<i class="layui-icon">&#xe608;</i> 添加机器人

				</a>

				<a href="javascript:;" class="layui-btn layui-btn-small" id="refresh">

					<i class="layui-icon">&#x1002;</i> 刷新

				</a>

			</blockquote>

			<fieldset class="layui-elem-field">

				<legend>用户列表</legend>

				<div class="layui-field-box">

					<table class="site-table table-hover">

						<thead>

							<tr>

								<th>头像</th>

								<th>昵称</th>

								<th>区域</th>

								<th>性别</th>

								<th>等级</th>

								<th>段位</th>

								<th>机器人</th>

								<th>状态</th>

								<th>操作</th>

							</tr>

						</thead>

						<tbody>

						</tbody>

					</table>



				</div>

			</fieldset>

			<div class="admin-table-page">

				<div id="page" class="page">

				</div>

			</div>

		</div>

		<script type="text/javascript" src="/addons/hc_answer/template/plugins/layui/layui.js"></script>

		<script>

			layui.config({

				base: '/addons/hc_answer/template/plugins/layui/modules/'

			});



			layui.use(['icheck', 'laypage','layer'], function() {

				var $ = layui.jquery,

					laypage = layui.laypage,

					layer = parent.layer === undefined ? layui.layer : parent.layer;

				$('input').iCheck({

					checkboxClass: 'icheckbox_flat-green'

				});



				//page

				laypage({
					cont: 'page',
					pages: {$nums},
					groups: 10,
					jump: function(obj, first) {
						//得到了当前页，用于向服务端请求对应数据
						var curr = obj.curr;
						var robot = $("#robot").val();
						var nickname= $("#nickname").val();
						var html ='';

						$.ajax({

				            url:"{php echo $this->createWebUrl('userajax');php}",

				            data:{page:curr,robot:robot,nickname:nickname},

				            type:"post",

				            dataType:"json",

				            success:function(data){

				            	layui.each(data.data, function(index, item){

				            		html += '<tr>';

				            		html += '<td><img src="'+item.avatar+'" style="width:50px" /></td>';

							      	html += '<td>'+item.nickname+'</td>';

							      	html += '<td>'+item.province+'-'+item.city+'</td>';

							      	html += '<td>'+item.gender+'</td>';

							      	html += '<td>'+item.level+'</td>';

							      	html += '<td>'+item.dan+'</td>';

							      	html += '<td>'+item.robot+'</td>';

							      	html += '<td>'+item.status+'</td>';

							      	html += '<td><a href="javascript:;" class="layui-btn layui-btn-mini" data-id="'+item.uid+'" id="edit">编辑</a>&nbsp;&nbsp;';
							      	if(item.status==1){
							      		html += '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-mini" data-id="'+item.uid+'" id="black">拉黑</a>&nbsp;&nbsp;';
							      	}else{
							      		html += '<a href="javascript:;" class="layui-btn layui-btn-warm layui-btn-mini" data-id="'+item.uid+'" id="unblack">取消拉黑</a>&nbsp;&nbsp;';
							      	}
							      	
							      	html += '<a href="javascript:;" data-id="'+item.uid+'" id="del" class="layui-btn layui-btn-danger layui-btn-mini">删除</a></td>';

							      	html += '</tr>';

							    });

							    $("tbody").html(html);

				            },

				            error:function(data){

				                layer.alert('请稍后重试', {icon: 5});

				            }

				        });

						

					}

				});



				$('#search').on('click', function() {

					var robot = $("#robot").val();

					var nickname= $("#nickname").val();

					var easy = $("#easy").val();

					location.href='./index.php?c=site&a=entry&do=user&m=hc_answer&robot='+robot+'&nickname='+nickname

				});

				$('#refresh').on('click', function() {

					location.reload();

				});

				$('#add').on('click', function() {

					layer.open({

					  type: 2,

					  area: ['65%', '90%'],

					  fixed: false, //不固定

					  maxmin: true,

					  content: './index.php?c=site&a=entry&do=useradd&m=hc_answer',

					  end: function () {

				        location.reload();

				      }

					});

				});



				$('tbody').on('click', '#edit',function() {

					var id = $(this).attr('data-id');

					layer.open({

					  type: 2,

					  area: ['65%', '90%'],

					  fixed: false, //不固定

					  maxmin: true,

					  content: './index.php?c=site&a=entry&do=useradd&m=hc_answer&id='+id,

					  end: function () {

				        location.reload();

				      }

					});

				});

				$('tbody').on('click', '#del',function() {

					var id = $(this).attr('data-id');

					layer.confirm('确定要删除吗？', {

						btn: ['确认','取消'],

						end: function () {

					        location.reload();

					    }

					}, function(){

						$.ajax({

				            url:"{php echo $this->createWebUrl('userdo');php}",

				            data:{id:id,act:'del'},

				            type:"post",

				            dataType:"json",

				            success:function(data){

				            	if(data.code=='1'){

				                	layer.alert(data.msg, {icon: 6});

				            	}else{

				                	layer.alert(data.msg, {icon: 5});

				            	}

				            },

				            error:function(data){

				                layer.alert('请稍后重试', {icon: 5});

				            }

				        });

					});

				});
				$('tbody').on('click', '#black',function() {

					var id = $(this).attr('data-id');

					layer.confirm('确定要拉黑吗？', {

						btn: ['确认','取消'],

						end: function () {

					        location.reload();

					    }

					}, function(){

						$.ajax({

				            url:"{php echo $this->createWebUrl('userdo');php}",

				            data:{id:id,act:'black'},

				            type:"post",

				            dataType:"json",

				            success:function(data){

				            	if(data.code=='1'){

				                	layer.alert(data.msg, {icon: 6});

				            	}else{

				                	layer.alert(data.msg, {icon: 5});

				            	}

				            },

				            error:function(data){

				                layer.alert('请稍后重试', {icon: 5});

				            }

				        });

					});

				});
				$('tbody').on('click', '#unblack',function() {

					var id = $(this).attr('data-id');

					layer.confirm('确定要取消拉黑吗？', {

						btn: ['确认','取消'],

						end: function () {

					        location.reload();

					    }

					}, function(){

						$.ajax({

				            url:"{php echo $this->createWebUrl('userdo');php}",

				            data:{id:id,act:'unblack'},

				            type:"post",

				            dataType:"json",

				            success:function(data){

				            	if(data.code=='1'){

				                	layer.alert(data.msg, {icon: 6});

				            	}else{

				                	layer.alert(data.msg, {icon: 5});

				            	}

				            },

				            error:function(data){

				                layer.alert('请稍后重试', {icon: 5});

				            }

				        });

					});

				});
				



			});

		</script>

	</body>



